/**
 */
package Alloy.impl;

import Alloy.AlloyPackage;
import Alloy.Relationship;
import Alloy.RelatorRuleset;
import Alloy.Universal;

import Alloy.Variable;
import java.util.Collection;
import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Relator Ruleset</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link Alloy.impl.RelatorRulesetImpl#getRelator <em>Relator</em>}</li>
 *   <li>{@link Alloy.impl.RelatorRulesetImpl#getRelata <em>Relata</em>}</li>
 *   <li>{@link Alloy.impl.RelatorRulesetImpl#getMediations <em>Mediations</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class RelatorRulesetImpl extends RulesetImpl implements RelatorRuleset {
	/**
	 * The cached value of the '{@link #getRelator() <em>Relator</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRelator()
	 * @generated
	 * @ordered
	 */
	protected Universal relator;

	/**
	 * The cached value of the '{@link #getRelata() <em>Relata</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRelata()
	 * @generated
	 * @ordered
	 */
	protected EList<Variable> relata;

	/**
	 * The cached value of the '{@link #getMediations() <em>Mediations</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMediations()
	 * @generated
	 * @ordered
	 */
	protected EList<Relationship> mediations;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected RelatorRulesetImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return AlloyPackage.Literals.RELATOR_RULESET;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Universal getRelator() {
		if (relator != null && relator.eIsProxy()) {
			InternalEObject oldRelator = (InternalEObject)relator;
			relator = (Universal)eResolveProxy(oldRelator);
			if (relator != oldRelator) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, AlloyPackage.RELATOR_RULESET__RELATOR, oldRelator, relator));
			}
		}
		return relator;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Universal basicGetRelator() {
		return relator;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setRelator(Universal newRelator) {
		Universal oldRelator = relator;
		relator = newRelator;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, AlloyPackage.RELATOR_RULESET__RELATOR, oldRelator, relator));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Variable> getRelata() {
		if (relata == null) {
			relata = new EObjectContainmentEList<Variable>(Variable.class, this, AlloyPackage.RELATOR_RULESET__RELATA);
		}
		return relata;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Relationship> getMediations() {
		if (mediations == null) {
			mediations = new EObjectContainmentEList<Relationship>(Relationship.class, this, AlloyPackage.RELATOR_RULESET__MEDIATIONS);
		}
		return mediations;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case AlloyPackage.RELATOR_RULESET__RELATA:
				return ((InternalEList<?>)getRelata()).basicRemove(otherEnd, msgs);
			case AlloyPackage.RELATOR_RULESET__MEDIATIONS:
				return ((InternalEList<?>)getMediations()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case AlloyPackage.RELATOR_RULESET__RELATOR:
				if (resolve) return getRelator();
				return basicGetRelator();
			case AlloyPackage.RELATOR_RULESET__RELATA:
				return getRelata();
			case AlloyPackage.RELATOR_RULESET__MEDIATIONS:
				return getMediations();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case AlloyPackage.RELATOR_RULESET__RELATOR:
				setRelator((Universal)newValue);
				return;
			case AlloyPackage.RELATOR_RULESET__RELATA:
				getRelata().clear();
				getRelata().addAll((Collection<? extends Variable>)newValue);
				return;
			case AlloyPackage.RELATOR_RULESET__MEDIATIONS:
				getMediations().clear();
				getMediations().addAll((Collection<? extends Relationship>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case AlloyPackage.RELATOR_RULESET__RELATOR:
				setRelator((Universal)null);
				return;
			case AlloyPackage.RELATOR_RULESET__RELATA:
				getRelata().clear();
				return;
			case AlloyPackage.RELATOR_RULESET__MEDIATIONS:
				getMediations().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case AlloyPackage.RELATOR_RULESET__RELATOR:
				return relator != null;
			case AlloyPackage.RELATOR_RULESET__RELATA:
				return relata != null && !relata.isEmpty();
			case AlloyPackage.RELATOR_RULESET__MEDIATIONS:
				return mediations != null && !mediations.isEmpty();
		}
		return super.eIsSet(featureID);
	}

} //RelatorRulesetImpl
